﻿using NicoViewLib.Model.Comments;
using NicoViewLib.Model.Comments.BodyTexts;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NicoViewUnitTest
{
    [TestFixture]
    public class BodyTextApiUnitTest
    {
        [TestCase]
        public void NicoAnchorHtmlTagBodyTextApiTest()
        {
            var videoUrl = "http://nicovideo.jp";
            var displayText = "こちらをクリック";
            var testValue = new NicoAnchorHtmlTagBodyText(displayText, videoUrl, null);
            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.AnchorHtmlTag);
            Assert.AreEqual(testValue.AsUrl(), videoUrl);
            Assert.AreEqual(testValue.Text, displayText);
            Assert.AreEqual(testValue.DisplayText, displayText);
            Assert.AreEqual(testValue.HasChildBodyTexts, true);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, true);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);
        }


        [TestCase]
        public void NicoBspCommandApiTest()
        {
            var displayText = "BSPコマンド";

            var testValue = new NicoBspCommand(displayText, null);

            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.BspCommand);
            Assert.AreEqual(testValue.HasChildBodyTexts, true);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.Text, displayText);
            Assert.AreEqual(testValue.DisplayText, displayText);
            Assert.AreEqual(testValue.HasChildBodyTexts, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, true);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, true);

        }

        [TestCase]
        public void NicoCommentCommandBodyTextApiTest()
        {
            var displayText = "テストコマンド";
            var testValue = new NicoCommentCommandBodyText(displayText);
            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.Command);
            Assert.AreEqual(testValue.DisplayText, displayText);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, true);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);
        }

        [TestCase]
        public void NicoComunityIdBodyTextApiTest()
        {
            var communityId="testCommunityId";
            var testValue = new NicoComunityIdBodyText(communityId);
            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.CommunityId);
            Assert.AreEqual(testValue.DisplayText, communityId);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);
        }


        [TestCase]
        public void NicoHtmlTagBodyTextApiTest()
        {
            var testValue = new NicoHtmlTagBodyText(null);
            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.HtmlTag);
            Assert.AreEqual(testValue.HasChildBodyTexts, true);
            Assert.AreEqual(testValue.HasCurrentBodyText, false);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);

        }

        [TestCase]
        public void NicoLineBreakBodyTextApiTest()
        {
            var lineBreak = "<br/>";
            var testValue = new NicoLineBreakBodyText(lineBreak);
            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.LineBreak);
            Assert.AreEqual(testValue.DisplayText, "\r\n");
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);
            Assert.AreEqual(testValue.Text, lineBreak);
        }

        [TestCase]
        public void NicoLiveIdBodyTextApiTest()
        {
            var liveId = "lv245566788";
            var testValue = new NicoLiveIdBodyText(liveId);
            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.LiveId);
            Assert.AreEqual(testValue.DisplayText, liveId);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
        }

        [TestCase]
        public void NicoNameRegistRequestBodyTextApiTest()
        {
            var nameRegistText = "@test";
            var name = "test";
            var testValue = new NicoNameRegistRequestBodyText(nameRegistText, name);

            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.NameRegistRequest);
            Assert.AreEqual(testValue.DisplayText, nameRegistText);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.GetUserName(), name);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, true);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);
        }

        [TestCase]
        public void NicoOwnerShowCommandApiTest()
        {
            var text = "/perm";
            var testValue = new NicoOwnerShowCommand(text, null);

            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.OwnerShowCommand);

            Assert.AreEqual(testValue.HasChildBodyTexts, true);
            Assert.AreEqual(testValue.DisplayText, text);
            Assert.AreEqual(testValue.Text, text);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, true);
            Assert.AreEqual(testValue.IsOwnerShowCommand, true);
            Assert.AreEqual(testValue.IsUserShowCommand, false);



        }

        [TestCase]
        public void NicoPlainBodyTextApiTest()
        {
            var text = "testtext";
            var testValue = new NicoPlainBodyText(text);

            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.Plain);
            Assert.AreEqual(testValue.DisplayText, text);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);
            Assert.AreEqual(testValue.Text, text);

        }


        [TestCase]
        public void NicoRangeNoAnchorBodyTextApiTest()
        {
            var startNo = 4;
            var endNo = 6;
            var testValue = new NicoRangeNoAnchorBodyText(startNo, endNo);

            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.RangeNoAnchor);
            Assert.AreEqual(testValue.DisplayText, ">>" + startNo + "-" + endNo);
            Assert.AreEqual(testValue.Text, ">>" + startNo + "-" + endNo);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);
        }

        [TestCase]
        public void NicoSingleNoAnchorBodyTextApiTest()
        {
            var noAnchor = 42;
            var testValue = new NicoSingleNoAnchorBodyText(noAnchor);

            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.SingleNoAnchor);
            Assert.AreEqual(testValue.DisplayText, ">>" + noAnchor);
            Assert.AreEqual(testValue.Text, ">>" + noAnchor);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);

        }

        [TestCase]
        public void NicoUrlBodyTextApiTest()
        {
            var urlText = "http://nicovideo.jp";
            var testValue = new NicoUrlBodyText(urlText);

            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.Url);
            Assert.AreEqual(testValue.DisplayText, urlText);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, true);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);
            Assert.AreEqual(testValue.Text, urlText);

        }

        [TestCase]
        public void NicoVideoIdBodyTextApiText()
        {
            var videoId = "sm256432321";
            var testValue = new NicoVideoIdBodyText(videoId);

            Assert.AreEqual(testValue.BodyType, NicoCommentBodyTextType.VideoId);
            Assert.AreEqual(testValue.DisplayText, videoId);
            Assert.AreEqual(testValue.Text, videoId);
            Assert.AreEqual(testValue.HasChildBodyTexts, false);
            Assert.AreEqual(testValue.HasCurrentBodyText, true);
            Assert.AreEqual(testValue.HasUrl, false);
            Assert.AreEqual(testValue.HasUserName, false);
            Assert.AreEqual(testValue.IsCommand, false);
            Assert.AreEqual(testValue.IsOwnerShowCommand, false);
            Assert.AreEqual(testValue.IsUserShowCommand, false);
           
        }
        
    }
}
